<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!--提交订单页面 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>订单处理 - 提交</title>

<!--<link rel="stylesheet" type="text/css" href="../css/style.css"/>-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/shopcar/css/topbar.css">
<link  rel="stylesheet" href="${pageContext.request.contextPath}/shopcar/css/order_confirm.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/shopcar/js/jquery-2.1.1.js"></script>
<script type="text/javascript">


  var address="";
  var username="";
  var phone="";
  function orderOk(){
  	
  	  var email = $('#usemail').val();
	  var url = "${pageContext.request.contextPath}/saveOrder?address="+address+"&username="+username+"&phone="+phone+"&massege="+$('#massege').val()+"&email="+email;
	  
	  url=encodeURI(encodeURI(url));
	  window.location.href=url;
   
  }

  
    function caculateMoney(){  
        var sumArray= $(".J_ItemTotal");
        //var sumArray= $(".J_ItemPrice");
        var totalCash=0.0;
        for(var i=0;i<sumArray.length;i++){
           var sum= sumArray[i].innerHTML;
           totalCash+=parseFloat(sum);
        }     
         document.getElementById("sumprice").innerHTML=totalCash;
         document.getElementById("sumprice2").innerHTML=totalCash;
   		
   		 var addr=$('input:radio[name="address"]:checked').val();	
		 var arr=addr.split('/');//注split可以用字符或字符串分割
		 address=arr[0];
		 username=arr[1];
		 phone=arr[2];
		 $(".detailInfo").text(address+'('+username+"  收"+')'+phone);
    }
    
  function addAddress(){
      document.getElementById("div_id").style.display="block"; 
  }
  
   var xmlHttpReq;
  function saveAddrees(){
 	  $('#div_id').hide();
 	  $.ajax({
			type:'POST',
			url:'${pageContext.request.contextPath}/addAddress',
			data:{
				name:$('#addName').val(),
			    Phone:$('#addPhone').val(),
			    address:$('#addAddress').val()
			},
			success:function(response,status,xhr){
			  var msg=eval('('+response+')');
			  var str="<div class='address-info'>"+
						"<input name='address' class='J_MakePoint' type='radio' value='' id='addrId_674944241' checked='checked'>"+
						"<label for='addrId_674944241' class='user-address'>"+msg.addrress+"("+msg.conName+ " 收)"+
						  "<em>"+msg.conPhone+"</em>"+
						  "<em id='address'></em></label></div>";

			   $('.J_DefaultAddr').append(str);
		       $('#J_AddrConfirm').text(msg.addrress+"("+msg.conName+ " 收)"+
						  +msg.conPhone);
			}
		});
      
 
  }


 $(function(){
	
	 $.ajax({
		    type:'POST',
			url:'${pageContext.request.contextPath}/queryAddress',
			data:{
				id:3
			},
			success:function(response,status,xhr){	
			  var msg=eval('('+response+')');
			  for(var i=0;i<msg.length;i++){
			  	 var str="<div class='address-info'>"+
						"<input name='address' class='J_MakePoint' type='radio' value='"+msg[i].addrress+'/'+msg[i].conName+'/'+msg[i].conPhone+"' id='addrId_674944241' checked='checked'>"+
						"<label for='addrId_674944241' class='user-address'>"+msg[i].addrress+"("+msg[i].conName+ " 收)"+
						  "<em>"+msg[i].conPhone+"</em>"+
						  "<em id='address'></em></label></div>";
			 	
			   	$('.J_DefaultAddr').append(str);
		     
			  }
			 
			}
			
		});
		$(".J_MakePoint").change(function(){
			var addr=$('input:radio[name="address"]:checked').val();
			
			var arr=addr.split('/');//注split可以用字符或字符串分割
			address=arr[0];
			username=arr[1];
			phone=arr[2];
			$(".detailInfo").text(address+'('+username+"  收"+')'+phone);
		});
});
	

 
</script>

</head>
<body onload="caculateMoney();">



   <div id="commonTopbar" class="commonTopbar">
     <div id="commonTopbar_welcome" class="bar_left" style="margin-left:100px">
         <blockquote><blockquote><address><a id="headpage" href="${pageContext.request.contextPath }/homepageAndDetail/index.jsp" target="_blank" style="color: rgb(22, 160, 133);">首页 
         </a></address></blockquote></blockquote>
     </div>
   </div>
<div id="page">
 <div id="content" class="grid-c">
	
		<div id="address" class="address" style="margin-top: 20px;" data-spm="2">
			
				<h3>确认交易地址</h3>
				<ul id="address-list" class="address-list">
					<li class="J_Addr J_MakePoint clearfix J_DefaultAddr " data-point-url="http://log.mmstat.com/buy.1.20">
					<c:forEach items="${Addr}" var="c" >
					<div class="address-info">
						<input name="address" class="J_MakePoint " type="radio" value="674944241" id="addrId_674944241" data-point-url="http://log.mmstat.com/buy.1.20" ah:params="id=674944241^^stationId=0^^address=湖北民族学院（信息工程学院） 男生宿舍楼5栋102^^postCode=445000^^addressee=朱万雄^^phone=^^mobile=18727717260^^areaCode=422801" checked="checked">
						<label for="addrId_674944241" class="user-address">
                            ${c.addrress }(
						  <em>( ${c.conName } 收) ${c.conPhone }</em>
						      <em id="address"></em>
						</label>						
					</div>
					</c:forEach>
					</li>
				</ul>
				<ul id="J_MoreAddress" class="address-list hidden">
				</ul>
				<div class="address-bar">
					<a href="javascript:addAddress();" class="new J_MakePoint" id="J_NewAddressBtn">添加地址</a>
					<div id="div_id" style="display:none">
					<table>
                        <tr>
                            <td>收货人姓名:</td>
                            <td><input type="text" id="addName" name="name"/></td>
                        </tr>
                        <tr>
                             <td>收货人电话:</td>
                             <td><input type="text" id="addPhone" name="phone"/></td>
                        </tr>
                         <tr>
                             <td>收货人地址:</td>
                             <td><input type="text" id="addAddress" name="address"/></td>
                        </tr>
                        <tr>
                             <td>
                             <input type="button" onclick="saveAddrees();" value="保存"/>
                              <input type="reset" value="重置"/>
                             </td>
                       </tr>
                       </table>
					
					</div>
				</div>
			
		</div>
		 	 
		<form id="J_Form" name="J_Form" action="/auction/order/unity_order_confirm.html" method="post">
			<div>
				<h3 class="dib">确认订单信息</h3>
				<table cellspacing="0" cellpadding="0" class="order-table" id="J_OrderTable" summary="统一下单订单信息区域">
				
				   <thead>
				     <tr>
					   <th class="s-title">
						  商品<hr/>
					   </th>
					   <th class="s-price">
						  单价(元)<hr/>
					   </th>
					   <th class="s-amount">
						  数量<hr/>
					   </th>
					   <th class="s-total">
						 小计(元)<hr/>
					   </th>
				     </tr>
				    </thead>
				    <tbody data-spm="3" class="J_Shop">
				     <c:forEach items="${carAll}" var="carinfo"  varStatus="c">
				      <input type="hidden" name="sellId" value="carinfo.userId"/>
				       <tr class="first">
					      <td colspan="5">
					      </td>
				       </tr>
				       <tr class="shop blue-line">
					      <td colspan="3">
                                                                 卖家：
						    <a class="J_ShopName J_MakePoint" style="color:#5cbdaa" data-point-url="" href="" target="_blank" title="大佬">"${carinfo.userName }"</a>
						    <span class="seller">联系卖家：<a href="" style="color:#5cbdaa" target="_blank" class="J_MakePoint" data-point-url="">${carinfo.useremail }</a></span>
						    <input type="hidden" id="usemail" value="${carinfo.useremail }" />
						    <span class="J_WangWang" data-nick="淘米魅" data-display="inline"></span>
					      </td>
					     <td colspan="2" class="promo">
						    <div>
							  <ul class="scrolling-promo-hint J_ScrollingPromoHint">
						      </ul>
						    </div>
					     </td>
				        </tr>
				     
				       <tr class="item">
					        <td class="s-title">
						       <a href="#" target="_blank" style="color:#5cbdaa" class="J_MakePoint" data-point-url="">
						         <img style="width:60px;heigth:30px;" src="${pageContext.request.contextPath}/${carinfo.goodsImg }" class="itempic">
						         <span class="title J_MakePoint" style="color:#5cbdaa" data-point-url="">&nbsp;&nbsp;&nbsp;&nbsp;"${carinfo.conName}"</span>
					           </a>
						       <div class="props">
							  
						       </div>
						       <div style="margin-top:2px">
							     <span style="color:gray;">确认订单后立刻通知卖家</span>
						       </div>
					        </td>
					        <td class="s-price" name="price">
						       <span class='price'>
						         <em class="style-normal-small-black J_ItemPrice" name="goodsprice"> ${carinfo.goodsPrice }</em>
						       </span>
						       <input type="hidden" name="costprice" value="1.00" class="J_CostPrice"/>
					        </td>
					        <td class="s-amount" data-point-url="" name="number">${carinfo.shopNum }</td>
					        <td class="s-total" name="sum">
						       <span class='price' name="sum">
						         <em class="style-normal-bold-red J_ItemTotal ">${carinfo.goodsPrice*carinfo.shopNum}</em>
						       </span>
					        </td>
				        </tr>
				        <tr class="item-service">
					        <td colspan="5" class="servicearea" style="display: none">
					        </td>
				        </tr>
				        </c:forEach>
				        <tr class="blue-line" style="height: 2px;">
					        <td colspan="5">
					        </td>
				        </tr>
				        <tr class="other other-line">
					        <td colspan="5">
						       <ul class="dib-wrap">
							      <li class="dib user-info">
							        <ul class="wrap">
								      <li>
								        <div class="field gbook">
									       <label class="label">给卖家留言：</label>
									       <textarea style="width:350px;height:80px;" title="选填：对本次交易的补充说明（建议填写已经和卖家达成一致的说明）" id="massege"></textarea>
								        </div>
								      </li>
							        </ul>
							      </li>
							      <li class="dib extra-info">
							        <div class="extra-area">
								      <ul class="dib-wrap">
									      <li class="dib title">交易方式：</li>
									      <li class="dib content">支付宝 、银行卡或微信交易</li>
								      </ul>
							        </div>
							        <div class="servicearea" style="display: none">
							        </div>
							        <div class="extra-area">
								      <ul class="dib-wrap">
									      <li class="dib title">订单处理：</li>
									      <li class="dib content">确认订单后立刻通知卖家</li>
								      </ul>
							        </div>
							        <div class="servicearea" style="display: none">
							        </div>
							       </li>
						       </ul>
					       </td>
				       </tr>
				       <tr class="shop-total blue-line">                                 
					       <td colspan="5" id="J_ActualFee"> 
					         <span class='price g_price '>
					           费用合计：     
						      <span>&yen;</span>
						        <label class="style-middle-bold-red J_ShopTotal" id="sumprice"></label>
						      </span>
					       </td>
			           </tr>
				   </tbody>
				   <tfoot>
				       <tr>
					       <td colspan="5">
						      <div class="order-go" data-spm="4">
							     <div class="J_AddressConfirm address-confirm">
								     <div class="kd-popup pop-back" style="margin-bottom: 40px;">
									    <div class="box">
										   <div class="bd">
											   <div class="point-in">
												  <em class="t" style="color:#5cbdaa">实付款：</em>
												  <span class='price g_price '>
												     <span>￥</span><label class="style-large-bold-red" id="sumprice2" ></label>
												  </span>
											   </div>
											    <ul>
												  <li>
												     <em>到货地址:</em>
												     <span id="J_AddrConfirm" class="detailInfo" style="word-break: break-all;">                                                                    
												     </span>
												  </li>
											    </ul>
										    </div>
										 
									      <a id="J_Go" class=" btn-go" data-point-url="" tabindex="0" title="点击此按钮，提交订单。" href="javascript:orderOk();">提交订单<b class="dpl-button"></b></a>
									    </div>
									     
								     </div>
							    </div>
						     </div>
					      </td>
				        </tr>
				    </tfoot>
				 </table>
			 </div>
		</form>
	</div>
</body>
</html>